home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 2
/
Nebula Two.iso
/
SourceCode
/
Crossword
/
Source
/
LeapfrogSquare.m
< prev
next >
Wrap
Text File
|
1995-06-12
|
1KB
|
90 lines
/*
File LeapfrogSquare.m
These are the squares used for leapfrog search. When backjumping past a square, the square remembers its current value and tries that value first the next time through.
*/
#import <appkit/appkit.h>
#import "Leapfrog.h"
#import "Crossword.h"
#import "Puzzle.h"
/* ———————————————————————————————————————————————————————————————————————————— */
#define position(i) ((wordPosition *) [words elementAt: i])
#define forword(c) ((c) == WILDCARD ? (c):(c) + 'a')
#define forcell(c) ((c) == WILDCARD ? EMPTY:(c) + 'A')
/* ———————————————————————————————————————————————————————————————————————————— */
@implementation LeapfrogSquare
- initPuzzle: (id) thePuzzle cell: (id) theCell
{
[super initPuzzle: thePuzzle cell: theCell];
last = WILDCARD;
return self;
}
- show
{
char symbol;
symbol = (last == WILDCARD) ? letter:last;
[[puzzle getCrossword] putLetter: forcell(symbol) inSquare: cell];
DPSFlush();
return self;
}
- (char) chooseLetter
{
char best;
if ((last != WILDCARD) && (count[last] != 0))
{
[self clearStatus: JUMPED];
best = last;
last = WILDCARD;
}
else
{
last = letter;
best = [super chooseLetter];
if (!injump) last = WILDCARD;
}
return best;
}
/* ———————————————————————————————————————————————————————————————————————————— */
- update
{
[super update];
if ((last != WILDCARD) && (count[last] == 0))
{
last = WILDCARD;
[self show];
}
return self;
}
@end